layui.use([ 'form', 'layer', 'jquery' ], function() {
	var form = layui.form, layer = parent.layer === undefined ? layui.layer : top.layer
			$ = layui.jquery;

	// 登陆
	form.on('submit(login)', function(data) {
		var btn = $(this);
		btn.text("登录中...").attr("disabled", "disabled").addClass("layui-disabled");
		setTimeout(function() {
			$.ajax({
				cache:true,
				type:"POST",
				url: "/iprint/admin/doLogin",
				async: true,
				contentType:"application/json;charset=utf-8",
				data: JSON.stringify(data.field),
				success: function(data) {
					if(data == '1') {
						location.href="/iprint/admin/index";
					} else if(data == '2') {
						layer.msg('用户名或密码不正确！');
						var url = "/iprint/loginCode?" + Math.random();
						$("#loginCode").prop("src", url);
						btn.text("登陆").attr("disabled", false).removeClass("layui-disabled");
					} else {
						layer.msg('验证码不正确！');
						var url = "/iprint/loginCode?" + Math.random();
						$("#loginCode").prop("src", url);
						btn.text("登录").attr("disabled", false).removeClass("layui-disabled");
					}
				}
			});
		}, 1000);
		return false;
	});

	// 表单输入效果
	$(".loginBody .input-item").click(function(e) {
		e.stopPropagation();
		$(this).addClass("layui-input-focus").find(".layui-input").focus();
	})
	$(".loginBody .layui-form-item .layui-input").focus(function() {
		$(this).parent().addClass("layui-input-focus");
	})
	$(".loginBody .layui-form-item .layui-input").blur(function() {
		$(this).parent().removeClass("layui-input-focus");
		if ($(this).val() != '') {
			$(this).parent().addClass("layui-input-active");
		} else {
			$(this).parent().removeClass("layui-input-active");
		}
	})
})
